/**
 * 
 */
package com.gragra.sampling.binary;
import java.io.BufferedReader;
import java.io.IOException;
import com.gragra.data.MixingCorpus;
import com.gragra.data.MixingCorpusBaseImplementation;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.EmptySegmentation;
/**
 * @author Christoph Teichmann
 * 21.09.2013
 */
public abstract class GeneratorForBinaryCorpus implements MakeCorpus
{
	/**
	 * 
	 */
	private final boolean sampleHead;
	/**
	 * @return the sampleHead
	 */
	public boolean sampleHead()
	{return this.sampleHead;}
	/**
	 * @return the conv
	 */
	public ConvertSample getConverter()
	{return this.conv.getNewConverter();}
	/**
	 * 
	 */
	private final ConverterFactory conv;
	/**
	 * @param sampleHead
	 * @param conv
	 */
	public GeneratorForBinaryCorpus(boolean sampleHead, ConverterFactory conv)
	{
		super();
		this.sampleHead = sampleHead;
		this.conv = conv;
	}
	/**
	 * 
	 */
	private final BaseGenerator bg = new BaseGenerator(new EmptySegmentation());
	/**
	 * 
	 * @param line
	 * @param smoothing 
	 * @return
	 */
	public abstract BinaryStructure makeBinaryStructure(String line,int threads, double smoothing);
	/**
	 * 
	 * @return
	 */
	public WordAndTagHolder transfer(String s)
	{return bg.transferSingle(s);}
	@Override
	public MixingCorpus<BinaryStructure> createCorpus(
			BufferedReader input, int threads, double proposalSmoothing)
			throws IOException
	{

		MixingCorpus<BinaryStructure> corp = new MixingCorpusBaseImplementation<BinaryStructure>();
		String line;
		while((line = input.readLine()) != null)
		{corp.addData(makeBinaryStructure(line,threads,proposalSmoothing));}
		return corp;
	}
}